/**
 * 脚本创建菜单
 */

import { createMenu } from "@/api/modules/sys";

const originParams = {
  remark: "",
  parentId: 0,
  name: "",
  nameEn: "",
  url: "",
  perms: "",
  typeId: 0, // 1696429206184919040 菜单   1696429277706190848 按钮
  icon: "",
  sort: 0,
  redirect: "", // 跳转地址
  component: "", // 组件文件路径
  activeMenu: "", // 当前激活菜单项的 name，自动高亮父级菜单
  isLink: "", // 是否外链
  isHide: false, // 是否隐藏
  isFull: false, // 是否全屏
  isAffix: false, // 是否固定
  isKeepAlive: false, // 是否缓存
  componentName: "" //组件名称
};

const mainMenu = [
  {
    name: "订单管理",
    params: {
      ...originParams,
      name: "订单管理",
      nameEn: "order",
      url: "/order",
      typeId: 1696429206184919040,
      componentName: "orderNext",
      icon: "DocumentCopy"
    },
    children: [
      {
        name: "订单管理",
        params: {
          ...originParams,
          name: "订单管理",
          nameEn: "order",
          url: "/order-next",
          typeId: 1696429206184919040,
          component: "/order/order/index",
          componentName: "orderNext",
          icon: "Document"
        }
      },
      {
        name: "日报记录",
        params: {
          ...originParams,
          name: "日报记录",
          nameEn: "daily",
          url: "/daily-next",
          typeId: 1696429206184919040,
          component: "/order/daily/index",
          componentName: "dailyNext",
          icon: "Document"
        }
      },
      {
        name: "问题跟踪",
        params: {
          ...originParams,
          name: "问题跟踪",
          nameEn: "track",
          url: "/track-next",
          typeId: 1696429206184919040,
          component: "/order/track/index",
          componentName: "trackNext",
          icon: "Document"
        }
      }
    ]
  }
];

/**
 * 睡眠函数
 */
const sleep = (time = 1000) => {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve();
    }, time);
  });
};
const create = async (id = 0, list) => {
  for (let i = 0; i < list.length; i++) {
    let { params, children } = list[i];
    params.parentId = id;
    await sleep(1500);
    const { data } = await createMenu(params);
    console.log(params);

    if (children?.length) {
      create(data.id, children);
    }
  }
};

create(0, mainMenu);
